{% extends "venclave/base.html" %}
{% load venclave_tags %}
{% load bundler_tags %}

{% block styles %}
  {{ block.super }}
  {% css "venclave-styles" "detail.css" %}
  {% css "venclave-styles" "exhibit.css" %}
{% endblock %}

{% block scripts %}
  {{ block.super }}
  {% javascript "venclave-scripts" "jquery-ui-1.7.1.custom.min.js" %}
  {% javascript "venclave-scripts" "request.js" %}
  {% defer %}
    <script type="text/javascript">
      venclave.request.upvote_url = "{% url venclave-upvote %}";
    </script>
  {% enddefer %}
{% endblock %}

{% block content %}

  <form method="post" action="{% url venclave-request %}">
    Name of movie or other media to request:
    <input type="text" size="40" name="name"/>
    <input type="submit" value="Submit Request"/>
    <input type="hidden" name="make_request" value="true"/>
  </form>

  <h2 class="table_title">Active Requests</h2>

  <table class="content-requests" id="active-requests">
    <tr>
      <th>Votes</th>
      <th>Content Name</th>
      <th>Requester</th>
      <th>Requested at</th>
      {% if request.user.is_staff %}
        <th width="50">Mark Satisfied</th>
      {% endif %}
    </tr>

    {% for content_request in active_requests %}
      <tr>
        <td class="vote-cell">
          <a href="#" onclick="venclave.request.upvote({{content_request.id}})"
              ><img src="/video/images/arrow_blue_up.png"/></a>
          <span id="votes_{{content_request.id}}">
            {{content_request.votes}}
          </span>
        </td>
        <td>{{ content_request.name }}</td>
        <td>{{ content_request.user.username }}</td>
        <td>{{ content_request.added|timesince }} ago</td>
        {% if request.user.is_staff %}
          <td>
            <form method="post" action="{% url venclave-request %}">
              <input type="hidden" name="mark_satisfied" value="true"/>
              <input type="hidden" name="id" value="{{ content_request.id }}"/>
              <input type="hidden" name="satisfied" value="true"/>
              <a href="#" onclick="this.parentNode.submit()">mark</a>
            </form>
          </td>
        {% endif %}
      </tr>
    {% endfor %}

  </table>

  <h2 class="table_title">Satisfied Requests</h2>

  <table class="content-requests" id="satisfied-requests">
    <tr>
      <th>Votes</th>
      <th>Content Name</th>
      <th>Requester</th>
      <th>Requested at</th>
      <th>Satisfied on</th>
      {% if request.user.is_staff %}
        <th width="50">Mark Unsatisfied</th>
      {% endif %}
    </tr>

    {% for content_request in satisfied_requests %}
      <tr>
        <td class="vote-cell">{{ content_request.votes }}</td>
        <td>{{ content_request.name }}</td>
        <td>{{ content_request.user.username }}</td>
        <td>{{ content_request.added|timesince }} ago</td>
        <td>{{ content_request.satisfied_on }} ago</td>
        {% if request.user.is_staff %}
          <td>
            <form method="post" action="{% url venclave-request %}">
              <input type="hidden" name="mark_satisfied" value="true"/>
              <input type="hidden" name="id" value="{{ content_request.id }}"/>
              <input type="hidden" name="satisfied" value="false"/>
              <a href="#" onclick="this.parentNode.submit()">unmark</a>
            </form>
          </td>
        {% endif %}
      </tr>
    {% endfor %}
  </table>

  <div id="error-box"></div>

{% endblock content %}
